<template>
  <section>
    <div class="model retrieval">
      <img :src="IMGBASE64.JIANSUOGUANLI2X" class="orange">
      <span class="title">检索管理</span>
      <div class="body">
        <el-input placeholder="请输入故障名称" v-model="typeName" size="small" class="input"></el-input>
        <el-button type="primary" @click="nameSearch" size="small">搜索</el-button>
        <div class="right">
          <el-button type="success" @click="newAdd" size="small">新增</el-button>
        </div>
      </div>
    </div>
    <div class="model mywork">
      <img :src="IMGBASE64.WODEGONGZUO2X" class="pink">
      <span class="title">故障列表</span>
      <div class="kong"></div>
      <template>
        <!-- <router-link to="/complete"></router-link> -->
        <el-table :data="tablemsg" style="width: 100%">
          <el-table-column prop="id" label="#" width="70" align="center"></el-table-column>
          <el-table-column prop="schoolId" label="课程编号" align="center"></el-table-column>
          <el-table-column prop="typeName" label="类别名称" align="center" :show-overflow-tooltip='true'></el-table-column>
          <el-table-column prop="repairName" label="维修人员" align="center" :show-overflow-tooltip='true'></el-table-column>
          <el-table-column label="操作" align="center">
            <template scope="scope">
              <el-button size="small">修改</el-button>
              <el-button size="small" @click="mDelete(scope.index, scope.row, $event)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          v-show="paging"
          @current-change="handleCurrentChange"
          :page-size="20"
          layout="prev, pager, next, jumper"
          :total="total"
          class="pull-right">
        </el-pagination>
      </template>
    </div>

    <div class="details" v-show="newShow">
      <img :src="IMGBASE64.GREENXINZENG2X" class="pink">
      <span class="title">新增类别</span>
      <el-button icon="el-icon-close" class="close" @click="newAdd()"></el-button>
      <div class="content">
        <div class="line">
          <span>类别名称</span>
          <input type="text" class="inputText" v-model="name">
        </div>
        <div class="line">
          <span>维修人员</span>
          <input type="text" class="inputText" v-model="people">
        </div>
      </div>
      <div class="bottom">
        <div class="left">
          <el-checkbox v-model="checked">继续新建</el-checkbox>
        </div>
        <div class="right">
          <el-button type="success" @click="keepAddData" size="small">确定</el-button>
          <el-button @click="newAdd" size="small">取消</el-button>
        </div>
      </div>
    </div>

    <transition name="modal-shadow">
      <div class="modal-backdrop" v-show="newShow"></div>
    </transition>
  </section>
</template>

<script>
export default {
  data () {
    return {
      typeName: null,
      repairName: null,
      newShow: false,
      name: null,
      people: null,
      checked: false,
      total: 0,
      page: 1,
      paging: true,
      tablemsg: [{
        id: '1',
        num: '1',
        name: '电子白板',
        people: '李俊义'
      },
      {
        id: '2',
        num: '2',
        name: '电子白板',
        people: '李俊义'
      },
      {
        id: '3',
        num: '3',
        name: '电子白板',
        people: '李俊义'
      }]
    }
  },
  mounted () {
    // let _cookie = document.cookie.split(';')
    // let _cookieArray = []
    // _cookie.forEach(v => {
    //   let _d = v.split('=')
    //   _cookieArray.push({
    //     key: _d[0],
    //     value: _d[1]
    //   })
    // })
    this.$http.post(this._httpUrl + 'fault/repair/type/query', {}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
      if (response.body.code === '000') {
        // console.log(response.data.data.content)
        this.tablemsg = response.data.data.rows
      } else if (response.body.code === '887') {
        this.$router.push('/')
      } else if (response.body.code === '889') {
        this.$router.push('/')
      }
    })
  },
  methods: {
    mDelete (index, row, ev) {
      // let _cookie = document.cookie.split(';')
      // let _cookieArray = []
      // _cookie.forEach(v => {
      //   let _d = v.split('=')
      //   _cookieArray.push({
      //     key: _d[0],
      //     value: _d[1]
      //   })
      // })
      this.$http.post(this._httpUrl + 'fault/repair/type/del?typeId=' + parseInt(ev.path[4].cells[0].innerText), {}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
      })
      this.tablemsg.splice(index, 1)
    },
    nameSearch () {
      // let _cookie = document.cookie.split(';')
      // let _cookieArray = []
      // _cookie.forEach(v => {
      //   let _d = v.split('=')
      //   _cookieArray.push({
      //     key: _d[0],
      //     value: _d[1]
      //   })
      // })
      this.$http.post(this._httpUrl + 'fault/repair/type/query', {
        page: this.page,
        rows: '20',
        typeName: this.typeName
      }, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
        if (response.body.code === '000') {
          // console.log(response.data.data.content)
          this.tablemsg = response.data.data.rows
        } else if (response.body.code === '887') {
          this.$router.push('/')
        } else if (response.body.code === '889') {
          this.$router.push('/')
        }
      })
    },
    newAdd () {
      this.newShow = !this.newShow
      this.people = null
      this.name = null
    },
    keepAddData () {
      // let _cookie = document.cookie.split(';')
      // let _cookieArray = []
      // _cookie.forEach(v => {
      //   let _d = v.split('=')
      //   _cookieArray.push({
      //     key: _d[0],
      //     value: _d[1]
      //   })
      // })
      this.$http.post(this._httpUrl + 'fault/repair/type/add', {
        typeName: this.name,
        repairName: this.people
      }, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
        this.$http.post(this._httpUrl + 'fault/repair/type/query', {}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
          if (response.body.code === '000') {
            // console.log(response.data.data.content)
            this.tablemsg = response.data.data.rows
          } else if (response.body.code === '887') {
            this.$router.push('/')
          } else if (response.body.code === '889') {
            this.$router.push('/')
          }
        })
      })
      if (this.checked === true) {
        this.name = null
        this.people = null
      } else {
        this.newShow = !this.newShow
      }
    },
    handleCurrentChange (val) {
      this.page = val
      this.getStudentNameData()
    }
  }
}
</script>

<style scoped>
  a[data-v-2222c222]
  {
    text-decoration: none;
  }
</style>
<style lang="less" scoped>
  header{
    .field{
      display: inline-block;
    }
    .right{
      width: 15%;
      float: right;
      .user{
        display: inline-block;
        margin-left: 20%;
      }
    }
  }
  .model{
    width: 98%;
    position: relative;
    background: #FFF;
    margin-left: 1%;
    margin-top: 60px;
    border-radius: 5px;
    padding-top: 10px;
    .body{
      .right{
        float: right;
      }
    }
  }
  .kong{
    padding: 20px;
  }
  .mywork{
    .pink{
      position: absolute;
      left: 2%;
      top: -20px;
    }
    .title{
      margin-left: 11%;
    }
  }
  .details{
    width: 35%;
    position: fixed;
    left: 50%;
    top: 150px;
    margin-left: -17%;
    background: #FFF;
    border-radius: 5px;
    padding-top: 20px;
    padding-bottom: 0;
    .inputText{
      width: 60%;
      border: 0;
      border-bottom: 1px solid #d7d7d7;
    }
    .pink{
      position: absolute;
      left: 2%;
      top: -20px;
    }
    .title{
      margin-left: 20%;
    }
    .content{
      margin-top: 35px;
      padding-left: 25px;
      .line{
        margin-bottom: 20px;
      }
    }
    .bottom{
      border-top: 1px solid #D7D7D7;
      margin-top: 20px;
      background: #F8F8F8;
      padding: 8px 0;
      margin-left: -10px;
      margin-right: -10px;
      border-radius: 0 0 5px 5px;
      .left{
        width: 50%;
        display: inline-block;
        margin-left: 2%;
      }
      .right{
        width: 43%;
        display: inline-block;
        text-align: right;
      }
    }
  }
  .input{
    width: 20%;
  }
</style>
